home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
mflms101.arc
/
PIPER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-25
|
3KB
|
97 lines
/************************************************************************/
/* */
/* PIPER - filename piper */
/* */
/* Outputs a list of fully-qualified filenames matching the input */
/* specification. */
/* */
/* Copyright 1989 by Robert B. Stout dba MicroFirm */
/* All rights reserved */
/* */
/************************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#include <mflfiles.h>
#define _A_ANY 0xff
LOGICAL recurse = FALSE;
void pipem(char *spec)
{
char path[MAX_FLEN], dummy[13], fname[MAX_FLEN], file[MAX_FLEN];
struct find_t ffblk;
fnsplit(spec, NULL, path, NULL, dummy, NULL, NULL);
/* First print all filenames except `dot' directories */
if (SUCCESS == _dos_findfirst(spec, _A_ANY, &ffblk)) do
{
if ('.' == ffblk.name[0])
continue;
if (path)
strcat(strcpy(fname, path), ffblk.name);
else strcat(strcpy(fname, ffblk.name), "\\");
flnorm(fname, file);
if (file)
puts(file);
/* If this was a directory, process it if /R selected */
if (!recurse || !(ffblk.attrib & _A_SUBDIR))
continue;
if (path)
strcat(strcpy(fname, path), ffblk.name);
else strcpy(fname, ffblk.name);
strcat(fname, "\\*.*");
pipem(fname);
} while (SUCCESS == _dos_findnext(&ffblk));
}
void blow_off(int ercode)
{
if (ercode)
putchar('\a');
puts("Usage: PIPER [/h] [/r] [d:][path]");
puts("options: /h - Help");
puts(" /r - Recursively process subdirectories");
exit(ercode);
}
main(int argc, char *argv[])
{
int n, argn = 0;
char fname[MAX_FLEN];
for (n = 1; n < argc; ++n)
{
if ('/' == argv[n][0])
{
switch (tolower(argv[n][1]))
{
case ('r'):
recurse = TRUE;
break;
case ('h'):
blow_off(0);
default:
blow_off(ERROR);
}
}
else if (!argn)
argn = n;
else blow_off(ERROR);
}
if (!argn)
pipem("*.*");
else
{
strcat(strcpy(fname, argv[argn]), "\\*.*");
pipem(fname);
}
}